﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using QLVMBAYDatacess;
using QLVMBAYDomain;
using System.Web.UI.WebControls;

namespace QLVMBAY
{
    public class ClientComm
    {
        static ClientComm ints=null;
        public static ClientComm Ints
        {
            get {
                if (ints == null)
                    ints = new ClientComm();
                return ints;
            }
        }
        public QuocGiaDA QuocGia
        {
            get { return new QuocGiaDA(); }
        }
        public ThanhPhoDA ThanhPho
        {
            get { return new ThanhPhoDA(); }
        }
        public ChuyenBayDA ChuyenBay { get { return new ChuyenBayDA(); } }

        public NguoiDungDA NguoiDung { get { return new NguoiDungDA(); } }

        public SanBayDA SanBay { get { return new SanBayDA(); } }

        public LoaiGheDA LoaiGhe { get { return new LoaiGheDA(); } }

        public const string KEY_TIM_VE = "K-TIM-VE";
        public const string KEY_TIM_KIEM = "K-TIM-KIEM";
        public const string KEY_DANG_NHAP = "K-DANG-NHAP";
        public const string KEY_THANH_TOAN = "K-TH/TOAN";
        public const string KEY_CHIEU_DI= "K-CHIEU_DI";
        public const string KEY_CHIEU_VE = "K-CHIEU_VE";
        public DateTime ToDate(string ddMMYYYY)
        {
            if (string.IsNullOrEmpty(ddMMYYYY)) return DateTime.MaxValue;
            if (ddMMYYYY.Replace("/", "").Trim() == "") return DateTime.MaxValue;
            try
            {
                int f1 = ddMMYYYY.IndexOf('/');
                int f2 = ddMMYYYY.LastIndexOf('/');
                if (f1 == f2) return DateTime.MaxValue;

                int day = Convert.ToInt16(ddMMYYYY.Substring(0, f1));
                int mon = Convert.ToInt16(ddMMYYYY.Substring(f1 + 1, f2 - f1 - 1));
                int yea = Convert.ToInt16(ddMMYYYY.Substring(f2 + 1, 4));
                return new DateTime(yea, mon, day);
            }
            catch
            {
                return DateTime.MaxValue;
            }
        }
        public DateTime ToDate(object date)
        {
            System.Globalization.DateTimeFormatInfo info = new System.Globalization.DateTimeFormatInfo();
            info.SetAllDateTimePatterns(new string[] { "dd/MM/yyyy hh:mm:ss tt" }, 'd');
            return Convert.ToDateTime(date, info);
        }
        public void LoadNgay(DropDownList ddlNgay,bool IsChon=false)
        {
            ddlNgay.Items.Clear();
            if (IsChon)
            {
                ddlNgay.Items.Add(new ListItem("Chọn", "0"));
            }
            for (int i = 1; i <= 31; i++)
            {
                ddlNgay.Items.Add(i.ToString());
            }
                        
        }
        public void LoadThang(DropDownList ddlThang,bool IsChon=false)
        {
            ddlThang.Items.Clear();
            if (IsChon)
            {
                ddlThang.Items.Add(new ListItem("Chọn", "0"));
            }
            for (int i = DateTime.Now.Month; i <= 12; i++)
            {
                ListItem item = new ListItem("Tháng " + i + " " + DateTime.Now.Year, i + "/" + DateTime.Now.Year);
                ddlThang.Items.Add(item);
            }
            for (int i = 1; i < DateTime.Now.Month; i++)
            {
                ListItem item = new ListItem("Tháng " + i + " " + (DateTime.Now.Year + 1), i + "/" + (DateTime.Now.Year + 1));
                ddlThang.Items.Add(item);
            }
        }
        public void LoadGio(DropDownList ddlGio, bool IsChon = false)
        {
            ddlGio.Items.Clear();
            if (IsChon)
            {
                ddlGio.Items.Add(new ListItem("00"));
            }
            for (int i = 0; i <= 24; i++)
            {
                ddlGio.Items.Add(i.ToString());
            }

        }
        public void LoadPhut(DropDownList ddlPhut, bool IsChon = false)
        {
            ddlPhut.Items.Clear();
            if (IsChon)
            {
                ddlPhut.Items.Add(new ListItem("00"));
            }
            for (int i = 0; i <= 60; i++)
            {
                ddlPhut.Items.Add(i.ToString());
            }

        }
    }
    public class TTinTimVe
    {
        public bool IsKhuHoi { get; set; }
        public string MaTPDi { get; set; }
        public string TenTPDi { get; set; }
        public string MaTPDen { get; set; }
        public string TenTPDen { get; set; }
        public DateTime ThoiGianDi { get; set; }
        public DateTime ThoiGianDen { get; set; }
        public int SLVe { get; set; }
        public int SLVeTrEm { get; set; }
    }
    public class TTTimKiem
    {
        public bool TimCB { get; set; }
        public string MaSB { get; set; }
        public string TenSB { get; set; }
        public bool ChieuDi { get; set; }
        public string MaLoaiGhe { get; set; }
        public string TenLoaiGhe { get; set; }
        public DateTime ThoiGianDi { get; set; }
        public DIEU_KIEN_TIM DKTim { get; set; }
        public float GiaVe { get; set; }
    }
    
}